package com.sumika.service;

import com.spring.anno.Component;
import com.spring.interfaces.BeanPostProcessor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: Asuka
 * @Description:
 * @create: 2025-04-08 23:23
 */

@Component
public class AopBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(String beanName,Object bean) {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(String beanName,Object bean) {

        Object instanceProxy = Proxy.newProxyInstance(AopBeanPostProcessor.class.getClassLoader(), bean.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("代理逻辑");
                return method.invoke(bean,args);
            }
        });


        return bean;
    }
}
